package com.example.chasshelper.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.chasshelper.ClassroomTeaActivity;
import com.example.chasshelper.JudgeTestActivity;
import com.example.chasshelper.MultipleChoiceTestActivity;
import com.example.chasshelper.R;
import com.example.chasshelper.SingleChoiceTestActivity;
import com.example.chasshelper.dao.ClassroomDao;
import com.example.chasshelper.dao.CourseDao;
import com.example.chasshelper.dao.MessageDao;
import com.example.chasshelper.dao.RegistrationDao;
import com.example.chasshelper.dao.SolutionDao;
import com.example.chasshelper.dao.StudentDao;
import com.example.chasshelper.dao.TeacherDao;
import com.example.chasshelper.dao.TestDao;
import com.example.chasshelper.model.Student;
import com.example.chasshelper.model.Teacher;
import com.example.chasshelper.model.Test;
import com.example.chasshelper.utils.DaoUtils;

import java.util.List;

public class TestTeaAdapter extends RecyclerView.Adapter<TestTeaAdapter.TestTeaViewHolder>{
    private Context mContext;
    //数据
    private List<Test> list;
    private Teacher teacher;
    private Student student;
    //dao
    private TeacherDao teacherDao= DaoUtils.getTeacherDao();
    private StudentDao studentDao=DaoUtils.getStudentDao();
    private CourseDao courseDao=DaoUtils.getCourseDao();
    private ClassroomDao classroomDao=DaoUtils.getClassroomDao();
    private RegistrationDao registrationDao=DaoUtils.getRegistrationDao();
    private SolutionDao solutionDao = DaoUtils.getSolutionDao();
    private MessageDao messageDao = DaoUtils.getMessageDao();
    private TestDao testDao = DaoUtils.getTestDao();

    public TestTeaAdapter(Context mContext, List<Test> list, Teacher teacher, Student student) {
        this.mContext = mContext;
        this.list = list;
        this.teacher = teacher;
        this.student = student;
    }

    public void setList(List<Test> list) {
        this.list = list;
    }

    /*
     * 绑定布局
     * */
    @NonNull
    @Override
    public TestTeaAdapter.TestTeaViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        TestTeaViewHolder testTeaViewHolder = new TestTeaViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_test_rv, parent, false));
        return testTeaViewHolder;
    }

    /*
     * 设置每一个item
     * */
    @Override
    public void onBindViewHolder(@NonNull TestTeaAdapter.TestTeaViewHolder holder, int position) {
        //回显
        Test test = list.get(position);
        holder.tv_id.setText(String.valueOf(test.getTestId()));
        holder.tv_content.setText("（"+test.getTestType()+"）"+test.getTestContext());
        //点击事件
        holder.ll_oneTest.setOnClickListener(new View.OnClickListener() {//进入题目，并传递数据
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("test",test);
                if (test.getTestType().equals("判断")) {
                    intent.setClass(mContext, JudgeTestActivity.class);
                }
                if (test.getTestType().equals("单选")) {
                    intent.setClass(mContext, SingleChoiceTestActivity.class);
                }
                if (test.getTestType().equals("多选")) {
                    intent.setClass(mContext, MultipleChoiceTestActivity.class);
                }
                mContext.startActivity(intent);
            }
        });

    }

    /*
     * 返回item数量
     * */
    @Override
    public int getItemCount() {
        return list.size();
    }


    /*
     * item布局
     * */
    class TestTeaViewHolder extends RecyclerView.ViewHolder {

        //控件
        CheckBox cb_select;
        TextView tv_id;
        TextView tv_content;
        LinearLayout ll_oneTest;
        public TestTeaViewHolder(@NonNull View itemView) {
            super(itemView);
            //绑定控件
            cb_select = itemView.findViewById(R.id.cb_select);
            tv_id = itemView.findViewById(R.id.tv_id);
            tv_content = itemView.findViewById(R.id.tv_content);
            ll_oneTest = itemView.findViewById(R.id.ll_oneTest);
        }
    }



}
